package com.chainyoung.component_tmperson.ui.mvp.presenter;

import com.chainyoung.common.appcommon.entity.HdWalletTokenCache;
import com.chainyoung.common.appcommon.hdwallet.TokenBalance;
import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.ui.mvp.contract.HdWalletTokenListContract;
import com.chainyoung.component_tmperson.ui.mvp.contract.HdWalletTokenTransactionContract;

import java.util.List;

import javax.inject.Inject;

public class HdWalletTokenTransactionPresenter extends BasePresenter<HdWalletTokenTransactionContract.Model, HdWalletTokenTransactionContract.View> {


    @Inject
    public HdWalletTokenTransactionPresenter(HdWalletTokenTransactionContract.Model model, HdWalletTokenTransactionContract.View rootView) {
        super(model, rootView);
    }


    public void getSingleTokenTransfers(String contractAddr, String address, int page, int offset) {
        addSubscribe(mModel.getSingleTokenTransfers(contractAddr, address, page, offset)
                .compose(RxUtils.<String>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<String>(mView) {
                    @Override
                    public void onNext(String data) {
                        mView.onGetSingleTokenTransfersSuccessed(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.onGetSingleTokenTrasferFailed();
                        super.onError(e);
                    }
                }));
    }


    public void getTokenBalance(final String contractAddr, String addr) {
        addSubscribe(mModel.getTokenBalance(contractAddr,addr)
                .compose(RxUtils.<TokenBalance>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<TokenBalance>(mView) {
                    @Override
                    public void onNext(TokenBalance data) {
                        mView.onGetTokenBalanceSuccessed(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.onGetTokenBalanceFailed(contractAddr);
                        super.onError(e);
                    }
                }));
    }

}

